package org.dromara.germbank.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.germbank.domain.BusOperationsAdvertisement;
import org.dromara.germbank.domain.bo.BusOperationsAdvertisementBo;
import org.dromara.germbank.domain.vo.BusOperationsAdvertisementVo;
import org.dromara.germbank.mapper.BusOperationsAdvertisementMapper;
import org.dromara.germbank.service.AdvertisementService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 广告管理imol实现类
 *
 * @author congxing
 */

@Slf4j
@RequiredArgsConstructor
@Service
public class AdvertisementServiceImpl implements AdvertisementService {

    private final BusOperationsAdvertisementMapper baseMapper;

    /**
     *  广告列表分页查询
     */

    @Override
    public TableDataInfo<BusOperationsAdvertisementVo> queryPageList(BusOperationsAdvertisementBo bo,
                                                                     PageQuery pageQuery) {
        Page<BusOperationsAdvertisementVo> page = baseMapper.queryPageList(pageQuery.build(),this.buildQueryWrapper(bo));
        return TableDataInfo.build(page);
    }

    /**
     * 校验广告名称是否唯一
     *
     * @param ad 广告信息
     * @return 结果
     */
    @Override
    public boolean checkAdNameUnique(BusOperationsAdvertisementBo ad) {
        return false;
    }

    /**
     * 新增保存广告信息
     *
     * @param bo 广告信息
     * @return 结果
     */
    @Override
    public int insertAd(BusOperationsAdvertisementBo bo) {
        return 0;
    }

    /**
     * 修改保存广告信息
     *
     * @param ad 广告信息
     * @return 结果
     */
    @Override
    public List<BusOperationsAdvertisementVo> updateDictData(BusOperationsAdvertisementBo ad) {
        return List.of();
    }

    /**
     * 批量删除广告数据信息
     *
     * @param adCodes 需要删除广告数据ID
     */
    @Override
    public void deleteAdDataByIds(List<Long> adCodes) {

    }

    //分页查询条件
    private Wrapper<BusOperationsAdvertisement> buildQueryWrapper(BusOperationsAdvertisementBo bo) {
        LambdaQueryWrapper<BusOperationsAdvertisement> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(BusOperationsAdvertisement::getDelFlag, SystemConstants.NORMAL)
            .like(org.dromara.common.core.utils.StringUtils.isNotBlank(bo.getName()), BusOperationsAdvertisement::getName, bo.getName())
            .eq(org.dromara.common.core.utils.StringUtils.isNotBlank(bo.getPage()), BusOperationsAdvertisement::getPage, bo.getPage())
            .like(org.dromara.common.core.utils.StringUtils.isNotBlank(bo.getPosition()), BusOperationsAdvertisement::getPosition, bo.getPosition())
            .orderByAsc(BusOperationsAdvertisement::getId);
        return wrapper;
    }
}
